<%@ page language="java" import="java.util.*" pageEncoding="UTF-8" %>
<% String path=request.getContextPath(); String basePath=request.getScheme()+ "://" + request.getServerName() + ":" + request.getServerPort() + path+ "/"; %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" >
<html  xmlns="http://www.w3.org/1999/xhtml">
<head>
    <base href="<%=basePath%>">
    <title>佣金确认单管理</title>
    <%@ include file="/WEB-INF/jsp/common/common.jsp" %>
    <script src="<%=path%>/js/jquery.divbox.js" type="text/javascript"></script>
    <script src="js/json2.js" type="text/javascript"></script>
    <script type="text/javascript">

        var uploadUrl='';

        $(document).ready(function () {
            $.ajax({
                url : "<%=path%>/commission/readyUploadUrl",
                type : 'POST',
                async : false,
                dataType:'json',
                success:function(data) {
                    uploadUrl = data.data;
                }
            });
        });

        function queryApplicationPage(pageIndex){

            if(pageIndex == null){
                pageIndex = 1;
            }

            var insurerId = $.trim($("#insurerId").val());//保险公司主键编号
            var id = $.trim($("#id").val());//确认单号
            var state = $.trim($("#state").val());//状态
            var approvalDateBegin = $.trim($("#approvalDateBegin").val());
            var approvalDateEnd = $.trim($("#approvalDateEnd").val());

            $.openLoading();
            $.ajax({
                url : "<%=path%>/commission/queryApplicationPage",
                type : 'POST',
                async : false,
                dataType:'json',
                data:{
                    pageIndex:pageIndex,
                    size:10,
                    insurerId:insurerId,
                    id:id,
                    state:state,
                    approvalDateBegin:approvalDateBegin,
                    approvalDateEnd:approvalDateEnd
                },
                success:function(page) {
                    $.closeLoading();
                    if($.validate(page)){
                        return;
                    }

                    var flag=page.obj
                    var firstbutton ='';
                    if(flag){
                        firstbutton ="<input class='input_fxk' name='radioUnionQCCode' type='radio' value='#'>@<input class='input_fxk' name='checkRule' type='checkBox' value='#'>";
                    }else{
                        firstbutton ="<input class='input_fxk' name='radioUnionQCCode' type='radio' value='#'>"
                    }
                    var lastbutton = "<a href='javascript:void(0)' onClick='toDetail(this);return false'>详情</a>";
                    var tableContent = creatTable1("insurerId,id,title,money,approvalDate,state",page,firstbutton,lastbutton);

                    var tableObj = $("#commissionTable");
                    tableObj.find("tbody").remove();
                    tableObj.append(tableContent);
                    var strPage = creatChannelPage(pageIndex,6,page.maxPage,"111");
                    var pageDIV = $("#commissionPageDiv");
                    pageDIV[0].innerHTML="";
                    pageDIV.append(strPage);
                }
            });
        }

        function reset() {
            $('#queryCommissionListForm input[type!="button"]').val("");
        }

        //--------------------下载-------------------------

        function openDownloadZJYDTemplate() {
            // 下载
            // 先查询确认的状态
            // 已核准，打开窗口选择下载’未核准的文件‘或’已核准的文件‘
            // 未核准或其他，直接下载’未核准的文件‘
            var selected = $("input[name='radioUnionQCCode']:checked");
            if(selected.length==0){
                $.message("error", "请选择一个佣金确认单");
                return;
            }
            var state = selected.parent('td').parent('tr')[0].childNodes[6].innerHTML;
            if ('异常' == state){
                $.message("error", "该确认单状态异常");
                return;
            }else if ('已核准' == state){
                $('#downloadDiv').OpenDiv();
            }else{
                this.downloadApply(0);
            }
        }

        function downloadApply(state) {

            //下载确认单
            var selected = $("input[name='radioUnionQCCode']:checked");
            var applyId = selected.parent('td').parent('tr')[0].childNodes[2].innerHTML;

            if (0 == state){
                downloadNotApply(applyId);
                return;
            }

            $.ajax({
                url : "<%=path%>/commission/downloadApply?applyId=" + applyId,
                type : 'POST',
                async : false,
                dataType : 'json',
                success:function (data) {
                    window.location.href = data.data;
                    $.message(data.result, data.message);
                },
                error:function (data) {
                    $.message(data.result, data.message);
                }
            })
        }


        function downloadNotApply(applyId) {
            $.ajax({
                url : "<%=path%>/commission/downloadNotApply",
                type : 'POST',
                async : false,
                dataType:'json',
                data:{
                    applyId:applyId
                },
                success:function (data) {
                    window.location.href = data.url;
                }
            })
        }

        function closeDownloadDiv(){
            $('#downloadDiv').CloseDiv();
        }

        //--------------------上传-------------------------

        function openUploadZJYDTemplate() {
            var selected = $("input[name='radioUnionQCCode']:checked");
            if(selected.length==0){
                $.message("error", "请选择一个佣金确认单");
                return;
            }
            var state = selected.parent('td').parent('tr')[0].childNodes[6].innerHTML;
            if ('异常' == state){
                $.message("error", "该确认单状态异常");
                return;
            }
            $('#uploadDiv').OpenDiv();
        }

        function toDetail(obj) {
            var detailTr = $(obj).parent('td').parent('tr')[0];
            var insurerId = detailTr.childNodes[1].innerHTML;//保险公司编号
            var applyId = detailTr.childNodes[2].innerHTML;//确认单号
            var state = detailTr.childNodes[6].innerHTML;//状态
            /*去详情页*/
            window.location.href="<%=path%>/commission/detail?applyId=" + applyId + "&insurerId=" + insurerId + "&state=" + encodeURI(encodeURI(state));
        }

        function closeUploadDiv(){
            $('#uploadDiv').CloseDiv();
        }

        function saveUpload() {
            $.openLoading();
            var filePath = $('#uploadFile').val() + "";
            if(filePath == ""){
                $.closeLoading();
                $.message("error","请选择文件");
                return;
            }

            /*var result = $('#result').val() + "";
            let numberReg = /^\d+$|^\d+[.]?\d+$/
            if (result !== '') {
                if (!numberReg.test(result)) {
                    $.closeLoading();
                    $.message("error","请输入数字");
                    return;
                }
            } else {
                $.closeLoading();
                $.message("error","请输入核定佣金金额");
                return;
            }*/

            var selected = $("input[name='radioUnionQCCode']:checked");
            var applyId = selected.parent('td').parent('tr')[0].childNodes[2].innerHTML;

            var formData = new FormData($("#uploadForm")[0]);
            $.ajax({
                /*上传后需要改状态为已核准*/
                url: this.uploadUrl + '?applyId=' + applyId,
                type:"POST",
                data:formData,
                dataType: "json",
                processData: false,// 告诉jQuery不要去处理发送的数据
                contentType: false,// 告诉jQuery不要去设置Content-Type请求头
                success:function (data) {
                    $.closeLoading();
                    $("#uploadFile").val('');
                    /*$("#result").val('');
                    $("#description").val('');*/
                    $.message(data.result, data.message);
                    $('#uploadDiv').CloseDiv();
                }
            });
        }
    </script>
</head>
<body>
    <div class="current">
        <table class="current_table_1">
            <tbody>
                <tr class="f2">
                    <td>
                        <img src="./images/current_1.jpg">
                    </td>
                    <td class="current_table_1_td">
                        <img src="images/current_1.png">&nbsp;您现在的位置：&nbsp;
                        <span style=" color:#136bab; ">中建英大
                              <span style="padding:0 5px; font-weight:bold; line-height:28px;">&gt;</span>佣金确认单管理
                        </span>
                    </td>
                    <td><img src="./images/current_3.jpg"></td>
                </tr>
            </tbody>
        </table>
    </div>

    <%--查询条件及结果表单--%>
    <table border="1" class="table_02" style="height:150px">
        <tr height="50px">
            <td colspan="2" align="center">
                <form method="post" id="queryCommissionListForm">
                    <table border="0" style="margin: 12px auto;">
                        <tr>
                            <td style="padding-left:40px; border: 0;text-align: right" nowrap="nowrap">保险公司编号：</td>
                            <td style="border: 0;text-align: left;padding-right: 70px">
                                <input name="insurerId" id="insurerId" class="input_text" style="width:130px;"/>
                            </td>

                            <td style="padding-left:40px;border: 0;text-align: right" nowrap="nowrap">确认单号：</td>
                            <td style="border: 0;text-align: left;padding-right: 70px">
                                <input name="id" id="id" class="input_text" style="width:130px;"/>
                            </td>

                            <td style="border: 0;text-align: right;" nowrap="nowrap">状态：</td>
                            <td style="border: 0;text-align: left;padding-right: 70px">
                                <select class="search_select_1" name="state" id="state">
                                    <option value="">---请选择---</option>
                                    <option value="0">未核准</option>
                                    <option value="1">已核准</option>
                                    <option value="2">异常</option>
                                </select>
                            </td>
                        </tr>
                        <tr>
                            <td style="border: 0;text-align: right;" nowrap="nowrap">核准日期：</td>
                            <td style="border: 0;text-align: left;padding-right: 70px">
                                <input id="approvalDateBegin" name="approvalDateBegin" readonly="readonly" onclick="showCalendar('approvalDateBegin','y-mm-dd');"  class="input_time"/>
                            </td>

                            <td style="border: 0;text-align: right;" nowrap="nowrap">至：</td>
                            <td style="border: 0;text-align: left;padding-right: 70px">
                                <input id="approvalDateEnd" name="approvalDateEnd" readonly="readonly" onclick="showCalendar('approvalDateEnd','y-mm-dd');"  class="input_time"/>
                            </td>
                        </tr>
                        <tr>
                            <td colspan="6" style="border: 0;padding-top: 5px;padding-right: 70px">
                                <input type="button"  class="input_button_1"  value="查询" onClick="queryApplicationPage()"/>
                                <input type="button"  class="input_button_1"  value="重置" onClick="reset()"/>
                            </td>
                        </tr>
                    </table>
                </form>
            </td>
        </tr>
        <tr>
            <td valign="top">
                <div id="commissionDiv" style="width:98%;margin:5px" >
                    <div align="left" style="margin:15px">
                        <input type="button"  class="input_button_1" value="下载" onClick="openDownloadZJYDTemplate()"/>&nbsp;
                        <input type="button"  class="input_button_1" value="上传" onClick="openUploadZJYDTemplate()"/>&nbsp;
                    </div>
                    <table class="table_02" id="commissionTable">
                        <thead>
                            <tr>
                                <th></th>
                                <th style="width:10%" nowrap="nowrap">保险公司编号</th>
                                <th style="width:20%" nowrap="nowrap">确认单号</th>
                                <th style="width:10%" nowrap="nowrap">确认标题</th>
<%--                                <th style="width:5%" nowrap="nowrap">佣金总额(元)</th>--%>
                                <th style="width:5%" nowrap="nowrap">提交确认总额(元)</th>
<%--                                <th style="width:5%" nowrap="nowrap">核定佣金总额(元)</th>--%>
                                <th style="width:15%" nowrap="nowrap">核准日期</th>
                                <th style="width:5%" nowrap="nowrap">状态</th>
                                <th style="width:5%" nowrap="nowrap">详情</th>
                            </tr>
                        </thead>
                        <tbody>
                        </tbody>
                    </table>
                    <%--分页--%>
                    <div id="commissionPageDiv"  class="page"></div>
                </div>
            </td>
        </tr>
    </table>

    <!--上传 DIV 默认隐藏-->
    <div id="uploadDiv"  style="display:none;width:400px;height: 200px">
        <input type="hidden" id="row_num" name="row_num" value="0"/>
        <div class="table_title_div">
            <table class="table_title" style='width:100%;'>
                <tr>
                    <td width="10%"></td>
                    <td width="80%" id="interfaceName"></td>
                    <td width="10%" align="right"><img src="<%=path%>/images/closedown.gif" alt="关闭"  onclick="closeUploadDiv()"/></td>
                </tr>
            </table>
        </div>

        <form id="uploadForm" action="save.jhtml" method="post" enctype="multipart/form-data">
            <table class="table_02" id="uploadDivTable" align="center" >
                <tbody>
                <tr style="height: 100px">
                    <td>
                        <input id="uploadFile" name="uploadFile" type='file' size='20'/>
                    </td>
                </tr>
                <%--<tr style="height: 50px">
                    <td>
                        核定佣金金额(元):<input type="text" id="result" name="result">
                    </td>
                </tr>
                <tr style="height: 200px">
                    <td colspan="2">
                        修正说明:<textarea id="description" name="description" rows="6" cols="10" style="height: 150px;width: 400px"></textarea>
                    </td>
                </tr>--%>
                </tbody>
            </table>
            <div align="center">
                <input class="input_button_3" name="" type="button" onclick="saveUpload()" value="上传">
                <input class="input_button_3" name="" type="button" onclick="closeUploadDiv()" value="取消">
            </div>
        </form>
    </div>

    <!--下载 DIV 默认隐藏-->
    <div id="downloadDiv"  style="display:none;width:400px;height: 200px">
        <input type="hidden" id="row_num2" name="row_num2" value="0"/>
        <div class="table_title_div">
            <table class="table_title" style='width:100%;'>
                <tr>
                    <td width="10%"></td>
                    <td width="80%" id="interfaceName2"></td>
                    <td width="10%" align="right"><img src="<%=path%>/images/closedown.gif" alt="关闭"  onclick="closeDownloadDiv()"/></td>
                </tr>
            </table>
        </div>

        <form id="downloadForm" action="save.jhtml" method="post" enctype="multipart/form-data">
            <table class="table_02" id="downloadDivTable" align="center" >
                <tbody>
                <tr style="height: 100px">
                    <td>
                        <input class="input_button_33"  type="button" onclick="downloadApply(1)" value="下载已核准确认单">
                    </td>
                    <td>
                        <input class="input_button_33"  type="button" onclick="downloadApply(0)" value="下载未核准确认单">
                    </td>
                </tr>
                </tbody>
            </table>
            <div align="center">
                <input class="input_button_3"  type="button" onclick="closeDownloadDiv()" value="取消">
            </div>
        </form>
    </div>

</body>
</html>
